#pragma once

#include "crow.h"
#include "crow/middlewares/utf-8.h"
#include "crow/middlewares/cookie_parser.h"
#include "languagehandlermiddleware.h"
#include "../tunnelconstructor.h"
#include "../notepad.h"

#include <string>

class HttpServer
{
public:
    HttpServer(const std::string& address, uint16_t port);
    void run();

private:
    void setup();

    crow::App<LanguageHandler, crow::CookieParser, crow::UTF8> app_;
    const std::string address_;
    const uint16_t port_;

    Notepad::Lang lang(const crow::request& req);
    std::pair<TunnelConstructor, bool> initTunnelConstructorViaUrlQuery(const crow::request& req, Notepad::Lang lang);
    std::string query(const crow::request& req);
    std::string mainPage(Notepad::Lang lang);
    std::string configPage(const std::string& generated, Notepad::Lang lang, bool comments, const std::string& query);
    std::string errorPage(const std::string& text, Notepad::Lang lang, const std::string& query);
};
